package Servlet.TeacherServlet;

import Entity.Teacher;
import Service.TeacherService.TeacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/*
负责教师 修改个人密码 数据接口
 */
@WebServlet(value = "/modifyTeacherPassword")
public class ModifyTeacherPassword extends HttpServlet {

    private TeacherService teacherService = new TeacherService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        String teacherId = request.getParameter("teacherId");
        String teacherPassword = request.getParameter("teacherPassword");
        System.out.println(teacherPassword);

        Teacher teacher = new Teacher(teacherId,teacherPassword);

        teacher = teacherService.modifyPasswordById(teacher);

        System.out.println(teacher);

        request.getSession().setAttribute("teacher", teacher);

        PrintWriter out = response.getWriter();
        out.print(1);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
